package studio.xiaoyun.web.restController;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import studio.xiaoyun.common.tool.NumberTool;
import studio.xiaoyun.web.RestResult;

import java.util.HashMap;
import java.util.Map;

/**
 * 为studio.xiaoyun.common包中的功能提供web接口
 * @author 岳正灵
 */
@RestController
@RequestMapping("/v1/common")
public class CommonRestController {

    /**
     * 将数字转换为中文大写。
     * <p>例如：将1.22转换为壹元贰角贰分</p>
     * @param number 数字
     * @return 中文大写格式的数字
     */
    @RequestMapping(value = "/numberToChinese", method = RequestMethod.GET)
    public RestResult numberToChinese(@RequestParam double number){
        String text = NumberTool.toChinese(number);
        Map<String,String> map = new HashMap<String,String>();
        map.put("value",text);
        RestResult restResult = new RestResult(1,map);
        return restResult;
    }

    /**
     * 将数字转换为英文大写
     * @param number 数字
     * @return 英文大写格式的数字
     */
    @RequestMapping(value = "/numberToEnglish", method = RequestMethod.GET)
    public RestResult numberToEnglish(@RequestParam double number){
        String text = NumberTool.toEnglish(number);
        Map<String,String> map = new HashMap<String,String>();
        map.put("value",text);
        RestResult restResult = new RestResult(1,map);
        return restResult;
    }

}
